<!DOCTYPE html>
<html>
  <head>
    <title>Mocha</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="mocha.css" />
  </head>
  <body>
	<div id="connection">Connecting to renoise...</div>
    <div id="mocha"></div>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
	<script src="../API/RenoiseWebControl.js"></script>
    <script src="mocha.js"></script>
	<script src="chai.js"></script>
    <script>mocha.setup('bdd')</script>
    <script src="tests.js"></script>
    <script>
	var assert = chai.assert,
		expect = chai.expect,
		should = chai.should()
	
	var timeout
	var conn = Renoise(function(_rns){
		clearTimeout(timeout)
		$("#connection").hide()
		
		// Make rns global
		rns = _rns
		mocha.globals(["rns"])
		
		// Add event capture stack
		rns.capturedCalls = []
		rns.responseReceived = null
		
		rns.onMessage(function(msg){
			rns.capturedCalls.push(msg)
			if(rns.responseReceived) {
				rns.responseReceived()
				rns.responseReceived = null
			}
		})
		
		mocha.run();
	})
	
	function tryConnecting() {
		conn.connect()
		timeout = setTimeout(tryConnecting, 3000)
	}
	
	tryConnecting()
    </script>
  </body>
</html>
